package com.zhangbo.share.web;

import com.zhangbo.share.dto.ResponseDTO;
import com.zhangbo.share.dubbo.api.IServiceApi;
import com.zhangbo.share.dubbo.dto.ResultInfoDTO;
import com.zhangbo.share.dubbo.vo.InputInfoVO;
import com.zhangbo.share.vo.RequestVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @auth zhangbo on 2022/10/22.
 */
@Slf4j
@RestController
@RequestMapping("/rest")
public class MyRestController {

    @DubboReference
    private IServiceApi serviceApi;

    /**
     * 测试rest post请求
     * @param requestVO
     * @return
     */
    @PostMapping("/post")
    public Object testPost(@RequestBody RequestVO requestVO) {
        log.info("方法接收到入参：{}",requestVO);

        InputInfoVO inputInfoVO = new InputInfoVO();
        inputInfoVO.setNage(requestVO.getName());
        inputInfoVO.setAge(requestVO.getAge());
        ResultInfoDTO call = serviceApi.call(inputInfoVO);

        return call;
    }

    /**
     * 测试rest get请求
     * @param requestVO
     * @return
     */
    @GetMapping("/get")
    public Object testGet(RequestVO requestVO) {
        log.info("方法接收到入参：{}",requestVO);

        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setResultCode(200);
        responseDTO.setResultMsg("成功");

        return responseDTO;
    }


}
